package com.edu.exam.entity.examination.paper;

import com.edu.exam.enums.exam.ExamType;
import com.edu.exam.enums.ItemStatus;
import jakarta.persistence.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 计划安排项实体类
 * 特殊考试计划中的具体安排项，存储详细的考试安排信息
 *
 * @author S-01 Module Designer
 * @version 2.0
 * @since 2025-11-10
 */
@Entity
@Data
@EqualsAndHashCode(callSuper = false)
public class PlanItem {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(name = "item_no", length = 50, unique = true, nullable = false)
    private String itemNo;

    @Column(name = "plan_id", nullable = false)
    private Long planId;

    @Column(name = "application_id", length = 50)
    private String applicationId;

    @Column(name = "student_id", length = 50, nullable = false)
    private String studentId;

    @Column(name = "student_name", length = 100)
    private String studentName;

    @Column(name = "course_id", length = 50, nullable = false)
    private String courseId;

    @Column(name = "course_name", length = 200)
    private String courseName;

    @Column(name = "exam_type", length = 50, nullable = false)
    private String examType;

    @Column(name = "exam_time")
    private LocalDateTime examTime;

    @Column(name = "exam_duration")
    private Integer examDuration; // 考试时长（分钟）

    @Column(name = "exam_location", length = 200)
    private String examLocation;

    @Column(name = "venue_id", length = 50)
    private String venueId;

    @Column(name = "venue_name", length = 200)
    private String venueName;

    @Column(name = "invigilator_id", length = 50)
    private String invigilatorId;

    @Column(name = "invigilator_name", length = 100)
    private String invigilatorName;

    @Column(name = "item_status", length = 50, nullable = false)
    private String itemStatus;

    @Column(name = "remarks", length = 500)
    private String remarks;

    @CreationTimestamp
    @Column(name = "created_time", nullable = false, updatable = false)
    private LocalDateTime createdTime;

    @UpdateTimestamp
    @Column(name = "updated_time")
    private LocalDateTime updatedTime;

    @Version
    @Column(name = "version", nullable = false)
    private Integer version = 1;

    // 关联实体
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "plan_id", insertable = false, updatable = false)
    private SpecialExamPlan plan;

    @OneToMany(mappedBy = "planItem", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    private List<ResourceReservation> resourceReservations;

}